home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaDemoCD1.iso / DEMOS / DEVIOUSDESIGN-bpIssue37.dms / in.adf / ­­>UTILITIES<­­ / Text Field.lha / Textfield / TestClass / TestClass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  17.6 KB  |  632 lines

  1. /*
  2.  * TestClass.c
  3.  *
  4.  * This is a sample program that uses the TextField BOOPSI class.
  5.  * It is modeled after an example in the RKRM Libraries book on
  6.  * the RKMButClass.  It is provided to show how to use a TextField.gadget
  7.  * BOOPSI object and shows general techniques and functionality.
  8.  *
  9.  * Opening the textfield.gadget library is done by TextFieldAuto.c.
  10.  * The variable TextFieldBase has the library base, and the variable
  11.  * TextFieldClass has the class pointer.
  12.  *
  13.  * See the autodoc if you do not use the SAS/C auto-open feature or
  14.  * if you have another compiler.
  15.  *
  16.  * This code compiles with SAS/C 6.51.
  17.  */
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. #include <exec/types.h>
  24. #include <intuition/intuition.h>
  25. #include <intuition/classes.h>
  26. #include <intuition/classusr.h>
  27. #include <intuition/imageclass.h>
  28. #include <intuition/gadgetclass.h>
  29. #include <intuition/cghooks.h>
  30. #include <intuition/icclass.h>
  31. #include <graphics/gfxmacros.h>
  32. #include <graphics/text.h>
  33. #include <utility/tagitem.h>
  34. #include <gadgets/textfield.h>
  35. #include <libraries/gadtools.h>
  36.  
  37. #include <clib/alib_protos.h>
  38.  
  39. #include <proto/exec.h>
  40. #include <proto/iffparse.h>
  41. #include <proto/intuition.h>
  42. #include <proto/graphics.h>
  43. #include <proto/utility.h>
  44. #include <proto/textfield.h>
  45. #include <proto/gadtools.h>
  46.  
  47. /*
  48.  * External prototypes
  49.  */
  50.  
  51. extern int SetupScreen( void );
  52. extern void CloseDownScreen( void );
  53. extern int HandleTextFieldPrefsIDCMP( void );
  54. extern int OpenTextFieldPrefsWindow( void );
  55. extern void CloseTextFieldPrefsWindow( void );
  56. extern struct Window *TextFieldPrefsWnd;
  57.  
  58. /*
  59.  * Local prototypes
  60.  */
  61.  
  62. static void MainLoop(void);
  63. static BOOL SetupPrefsWindow(void);
  64. static void ShutdownPrefsWindow(void);
  65. static void GetGadgetRect(struct Window *window, struct Gadget *gadget, struct Rectangle *rect);
  66. static void ActivateTabGadget(struct Window *window);
  67. static BOOL DoMenu(UWORD menu, UWORD item);
  68.  
  69. /*
  70.  * Local variables
  71.  */
  72.  
  73. static const char vers[] = "\0$VER: TestTextfield 3.0 " __AMIGADATE__;
  74. //static const char vers[] = "\0$VER: TestTextfield 2.0 (12.11.94)";
  75. static struct IntuiText text1_title;
  76. static struct DrawInfo *draw_info;
  77. static struct ClipboardHandle *clip_handle, *undo_handle;
  78. static struct Image *up_image, *down_image;
  79. static struct IntuiMessage *msg;
  80. static struct Menu *menu_strip;
  81. static APTR *visual_info;
  82. static unsigned char *text_buffer, *my_buffer;
  83. static UWORD gap_w, gap_h;
  84.  
  85. static char initial_text[] = "Sample text placed immediately into the gadget.\nType into the object.\nOr try AMIGA-[, AMIGA-=, AMIGA-], or AMIGA-\\.\n",
  86.             more_text[] = "I think the gadget looks best with the double-bevel border and a medium cursor speed.";
  87.  
  88. static struct TagItem prop2text[] = {
  89.     { PGA_Top, TEXTFIELD_Top },
  90.     { TAG_DONE }
  91. };
  92. static struct TagItem text2prop[] = {
  93.     { TEXTFIELD_Top, PGA_Top },
  94.     { TEXTFIELD_Visible, PGA_Visible },
  95.     { TEXTFIELD_Lines, PGA_Total },
  96.     { TAG_DONE }
  97. };
  98. static struct TagItem up2text[] = {
  99.     { GA_ID, TEXTFIELD_Up },
  100.     { TAG_DONE }
  101. };
  102. static struct TagItem down2text[] = {
  103.     { GA_ID, TEXTFIELD_Down },
  104.     { TAG_DONE }
  105. };
  106.  
  107. enum {
  108.     PROJECT_MENU,
  109.     EDIT_MENU,
  110. };
  111.  
  112. enum {
  113.     ABOUT_ITEM,
  114.     QUIT_ITEM = 2
  115. };
  116.  
  117. enum {
  118.     CUT_ITEM,
  119.     COPY_ITEM,
  120.     COPYALL_ITEM,
  121.     PASTE_ITEM,
  122.     UNDO_ITEM = 5,
  123.     ERASE_ITEM = 7
  124. };
  125.  
  126. static struct NewMenu menus[] = {
  127.     { NM_TITLE, "Project",          0, 0, 0, 0 },
  128.     {  NM_ITEM, "About",        "?", 0, 0, 0 },
  129.     {  NM_ITEM, NM_BARLABEL,      0, 0, 0, 0 },
  130.     {  NM_ITEM, "Quit",            "Q", 0, 0, 0 },
  131.     { NM_TITLE, "Edit",              0, 0, 0, 0 },
  132.     {  NM_ITEM, "Cut",            "X", 0, 0, 0 },
  133.     {  NM_ITEM, "Copy",            "C", 0, 0, 0 },
  134.     {  NM_ITEM, "Copy All",        "K", 0, 0, 0 },
  135.     {  NM_ITEM, "Paste",        "V", 0, 0, 0 },
  136.     {  NM_ITEM, NM_BARLABEL,      0, 0, 0, 0 },
  137.     {  NM_ITEM, "Undo",            "U", 0, 0, 0 },
  138.     {  NM_ITEM, NM_BARLABEL,      0, 0, 0, 0 },
  139.     {  NM_ITEM, "Erase",        "E", 0, 0, 0 },
  140.     {   NM_END, NULL,              0, 0, 0, 0 }
  141. };
  142.  
  143. static struct EasyStruct about_req = {
  144.     sizeof(struct EasyStruct),
  145.     0,
  146.     "About TestTextField",
  147.     "TestTextField shows how to\nuse the textfield gadget.\n\n%s",
  148.     "Okay"
  149. };
  150.  
  151. /*
  152.  * Global variables
  153.  */
  154.  
  155. struct Window *window;
  156. struct Gadget *text1_object, *prop_object, *up_object, *down_object;
  157. ULONG length, window_sig, prefs_sig, sigs, style;
  158. UWORD *pens;
  159.  
  160. /*
  161.  * Functions
  162.  */
  163.  
  164. void main(void)
  165. {
  166.     if (!SetupPrefsWindow()) {
  167.         printf("Cannot setup prefs window.\n");
  168.         return;
  169.     }
  170.     prefs_sig = 1L << TextFieldPrefsWnd->UserPort->mp_SigBit;
  171.  
  172.     /* Open the window */
  173.     window = OpenWindowTags(NULL,    WA_Flags,            WFLG_DEPTHGADGET|WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SIZEGADGET
  174.                                                         |WFLG_SIZEBBOTTOM|WFLG_SIZEBRIGHT,
  175.                                     WA_Activate,        TRUE,
  176.                                     WA_IDCMP,            IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_MENUPICK,
  177.                                     WA_Width,            320,
  178.                                     WA_Height,            200,
  179.                                     WA_NoCareRefresh,    TRUE,
  180.                                     WA_NewLookMenus,    TRUE,
  181.                                     WA_ScreenTitle,        "Testing textfield.gadget",
  182.                                     TAG_END);
  183.  
  184.     if (window) {
  185.         window_sig = 1L << window->UserPort->mp_SigBit;
  186.         sigs = prefs_sig | window_sig;
  187.         /* Get the DrawInfo since sysiclass needs it */
  188.         draw_info = GetScreenDrawInfo(window->WScreen);
  189.  
  190.         if (draw_info) {
  191.             pens = draw_info->dri_Pens;
  192.  
  193.             /* Make a title for the gadget */
  194.             text1_title.FrontPen = pens[TEXTPEN];
  195.             text1_title.BackPen = pens[BACKGROUNDPEN];  /* don't really need to set for JAM1 */
  196.             text1_title.DrawMode = JAM1;
  197.             text1_title.LeftEdge = 0;
  198.             text1_title.TopEdge = -(window->WScreen->RastPort.TxHeight + 1);
  199.             text1_title.ITextFont = NULL;
  200.             text1_title.IText = "Gadget label:";
  201.             text1_title.NextText = NULL;
  202.  
  203.             /* Setup the gaps */
  204.             gap_w = 20;
  205.             gap_h = window->RPort->TxHeight;
  206.  
  207.             /* Make some changes in the window limits */
  208.             WindowLimits(window, 160, window->BorderTop + window->BorderBottom + window->WScreen->RastPort.TxHeight + 46, -1, -1);
  209.  
  210.             /* Create the gadgets/images with interconnection */
  211.             prop_object = NewObject(NULL, "propgclass",
  212.                                     GA_ID,            2,
  213.                                     GA_Top,            window->BorderTop,
  214.                                     GA_RelRight,    -(window->BorderRight - 5),
  215.                                     GA_Width,        window->BorderRight - 8,
  216.                                     GA_RelHeight,    -(window->BorderTop + (3 * window->BorderBottom)) - 2,
  217.                                     GA_RightBorder,    TRUE,
  218.                                     ICA_MAP,        prop2text,
  219.                                     PGA_NewLook,    TRUE,
  220.                                     PGA_Borderless,    TRUE,
  221.                                     PGA_Visible,    50,        /* will get set later */
  222.                                     PGA_Total,        50,        /* will get set later */
  223.                                     TAG_END);
  224.  
  225.             up_image = NewObject(NULL, "sysiclass",
  226.                                     SYSIA_DrawInfo,    draw_info,
  227.                                     SYSIA_Which,    UPIMAGE,
  228.                                     IA_Width,        window->BorderRight,
  229.                                     IA_Height,        window->BorderBottom,
  230.                                     TAG_END);
  231.  
  232.             down_image = NewObject(NULL, "sysiclass",
  233.                                     SYSIA_DrawInfo,    draw_info,
  234.                                     SYSIA_Which,    DOWNIMAGE,
  235.                                     IA_Width,        window->BorderRight,
  236.                                     IA_Height,        window->BorderBottom,
  237.                                     TAG_END);
  238.  
  239.             up_object = NewObject(NULL, "buttongclass",
  240.                                     GA_RelBottom,    -(3 * window->BorderBottom) - 1,
  241.                                     GA_RelRight,    -(window->BorderRight - 1),
  242.                                     GA_Height,        window->BorderBottom,
  243.                                     GA_Width,        window->BorderRight,
  244.                                     GA_Image,        up_image,
  245.                                     GA_RightBorder,    TRUE,
  246.                                     //GA_RelVerify,    TRUE,
  247.                                     GA_Previous,    prop_object,
  248.                                     ICA_MAP,        up2text,
  249.                                     TAG_END);
  250.  
  251.             down_object = NewObject(NULL, "buttongclass",
  252.                                     GA_RelBottom,    -(2 * window->BorderBottom),
  253.                                     GA_RelRight,    -(window->BorderRight - 1),
  254.                                     GA_Height,        window->BorderBottom,
  255.                                     GA_Width,        window->BorderRight,
  256.                                     GA_Image,        down_image,
  257.                                     GA_RightBorder,    TRUE,
  258.                                     //GA_RelVerify,    TRUE,
  259.                                     GA_Previous,    up_object,
  260.                                     ICA_MAP,        down2text,
  261.                                     TAG_END);
  262.  
  263.             /* Open the clipboard; no need to verify */
  264.             clip_handle = OpenClipboard(0);
  265.             undo_handle = OpenClipboard(42);
  266.  
  267.             text1_object = NewObject(TextFieldClass, NULL,
  268.                                     GA_ID,                    1,
  269.                                     GA_Top,                    window->BorderTop + gap_h,
  270.                                     GA_Left,                window->BorderLeft + gap_w,
  271.                                     GA_RelWidth,            -(window->BorderLeft + window->BorderRight + 2 * gap_w),
  272.                                     GA_RelHeight,            -(window->BorderTop + window->BorderBottom + 2 * gap_h),
  273.                                     GA_Previous,            down_object,
  274.                                     GA_TabCycle,            TRUE,
  275.                                     GA_IntuiText,            &text1_title,
  276.  
  277.                                     ICA_MAP,                text2prop,
  278.                                     ICA_TARGET,                prop_object,
  279.  
  280.                                     TEXTFIELD_Text,            (ULONG)initial_text,
  281.                                     TEXTFIELD_UserAlign,    TRUE,
  282.                                     TEXTFIELD_ClipStream,    clip_handle,
  283.                                     TEXTFIELD_UndoStream,    undo_handle,
  284.                                     TEXTFIELD_Border,        TEXTFIELD_BORDER_DOUBLEBEVEL,
  285.                                     TEXTFIELD_BlinkRate,    500000,
  286.                                     TEXTFIELD_TabSpaces,    4,
  287.                                     TEXTFIELD_NonPrintChars,    TRUE,
  288.  
  289.                                     /*TEXTFIELD_VCenter,        TRUE,
  290.                                     TEXTFIELD_CursorPos,    10,
  291.                                     TEXTFIELD_Partial,        TRUE,
  292.                                     TEXTFIELD_MaxSize,        1000,
  293.                                     TEXTFIELD_AcceptChars,    "+-1234567890\n",
  294.                                     TEXTFIELD_Alignment,    TEXTFIELD_ALIGN_CENTER,
  295.                                     TEXTFIELD_TextAttr,        (ULONG)&font,
  296.                                     TEXTFIELD_Spacing,        10,
  297.                                     TEXTFIELD_FontStyle,    style,*/
  298.                                     TAG_END);
  299.  
  300.             /* Check if they were all created okay */
  301.             if (text1_object && prop_object && up_image && down_image && up_object && down_object) {
  302.                 ULONG cur;
  303.  
  304.                 /* Do menu stuff */
  305.                 visual_info = GetVisualInfo(window->WScreen, TAG_END);
  306.                 if (visual_info) {
  307.                     menu_strip = CreateMenus(menus, TAG_END);
  308.                     if (menu_strip) {
  309.                         if (LayoutMenus(menu_strip, visual_info, GTMN_NewLookMenus, TRUE, TAG_END)) {
  310.                             if (!SetMenuStrip(window, menu_strip)) {
  311.                                 printf("Can't set menu strip; no menus.\n");
  312.                             }
  313.                         } else {
  314.                             printf("Can't layout menus; no menus.\n");
  315.                         }
  316.                     } else {
  317.                         printf("Can't create menus; no menus.\n");
  318.                     }
  319.                 } else {
  320.                     printf("Can't get visual info; no menus.\n");
  321.                 }
  322.  
  323.                 /* Adjust some of the interconnections */
  324.                 SetGadgetAttrs(prop_object, window, NULL, ICA_TARGET, text1_object, TAG_END);
  325.                 SetGadgetAttrs(up_object, window, NULL, ICA_TARGET, text1_object, TAG_END);
  326.                 SetGadgetAttrs(down_object, window, NULL, ICA_TARGET, text1_object, TAG_END);
  327.  
  328.                 AddGList(window, prop_object, -1, -1, NULL);
  329.                 RefreshGList(prop_object, window, NULL, -1);
  330.  
  331.                 ActivateGadget(text1_object, window, NULL);
  332.                 SetWindowTitles(window, "<-- Scroll to bottom; click to go to top", (UBYTE *)-1);
  333.                 MainLoop();
  334.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_CursorPos, 0, TAG_DONE);
  335.  
  336.                 ActivateGadget(text1_object, window, NULL);
  337.                 SetWindowTitles(window, "<-- Move cursor; click to remember", (UBYTE *)-1);
  338.                 MainLoop();
  339.                 GetAttr(TEXTFIELD_CursorPos, text1_object, &cur);
  340.  
  341.                 SetWindowTitles(window, "<-- Click to reset cursor", (UBYTE *)-1);
  342.                 MainLoop();
  343.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_CursorPos, cur, TAG_DONE);
  344.                 ActivateGadget(text1_object, window, NULL);
  345.  
  346.                 SetWindowTitles(window, "<-- Click to move gadget position", (UBYTE *)-1);
  347.                 MainLoop();
  348.                 { // Shows how to change the size on the fly
  349.                   // Also shows the special case of handling size change with GA_Rel#?
  350.                     struct Rectangle rect;
  351.  
  352.                     GetGadgetRect(window, text1_object, &rect);
  353.                     SetAPen(window->RPort, pens[BACKGROUNDPEN]);
  354.                     RectFill(window->RPort, rect.MinX, rect.MinY, rect.MaxX, rect.MaxY);
  355.                     SetGadgetAttrs(text1_object, window, NULL,
  356.                                     GA_Left,        window->BorderLeft,
  357.                                     GA_Top,            window->BorderTop,
  358.                                     GA_RelWidth,    -(window->BorderLeft + window->BorderRight),
  359.                                     GA_RelHeight,    -(window->BorderTop + window->BorderBottom),
  360.                                     GA_IntuiText,    NULL,
  361.                                     TAG_DONE);
  362.                     RefreshGList(text1_object, window, NULL, 1);
  363.                 }
  364.                 //ActivateGadget(text1_object, window, NULL);
  365.  
  366.                 SetWindowTitles(window, "<-- Click to replace text", (UBYTE *)-1);
  367.                 MainLoop();
  368.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_Text, more_text, TAG_DONE);
  369.                 //ActivateGadget(text1_object, window, NULL);
  370.  
  371.                 SetWindowTitles(window, "<-- Click to select 10 chars", (UBYTE *)-1);
  372.                 MainLoop();
  373.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_SelectSize, 10, TAG_DONE);
  374.                 ActivateGadget(text1_object, window, NULL);
  375.  
  376.                 SetWindowTitles(window, "<-- Click to print text and info", (UBYTE *)-1);
  377.                 MainLoop();
  378.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_ReadOnly, TRUE, TAG_DONE);
  379.                 if (GetAttr(TEXTFIELD_Size, text1_object, &length)) {
  380.                     my_buffer = malloc(length + 1);
  381.                     if (my_buffer) {
  382.                         my_buffer[length] = 0;
  383.                         if (GetAttr(TEXTFIELD_Text, text1_object, (ULONG *)&text_buffer)) {
  384.                             if (text_buffer) {
  385.                                 memcpy(my_buffer, text_buffer, length);
  386.                                 printf("%s", my_buffer);
  387.                                 printf("\n");
  388.                             }
  389.                         }
  390.                         free(my_buffer);
  391.                     }
  392.                 }
  393.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_ReadOnly, FALSE, TAG_DONE);
  394.                 if (GetAttr(TEXTFIELD_Visible, text1_object, &length)) {
  395.                     printf("Visible lines: %d\n", length);
  396.                 }
  397.                 if (GetAttr(TEXTFIELD_Lines, text1_object, &length)) {
  398.                     printf("  Total lines: %d\n", length);
  399.                 }
  400.                 if (GetAttr(TEXTFIELD_Size, text1_object, &length)) {
  401.                     printf("         Size: %d\n", length);
  402.                 }
  403.                 if (GetAttr(TEXTFIELD_Top, text1_object, &length)) {
  404.                     printf("     Top line: %d\n", length);
  405.                 }
  406.                 if (GetAttr(TEXTFIELD_CursorPos, text1_object, &length)) {
  407.                     printf("       Cursor: %d\n", length);
  408.                 }
  409.  
  410.                 SetWindowTitles(window, "<-- Click to quit", (UBYTE *)-1);
  411.                 MainLoop();
  412.  
  413.                 RemoveGList(window, prop_object, -1);
  414.  
  415.                 /* Clean menu stuff */
  416.                 if (window->MenuStrip) {
  417.                     ClearMenuStrip(window);
  418.                 }
  419.                 if (menu_strip) {
  420.                     FreeMenus(menu_strip);
  421.                 }
  422.                 if (visual_info) {
  423.                     FreeVisualInfo(visual_info);
  424.                 }
  425.             } else {
  426.                 printf("Couldn't get objects.\n");
  427.             }
  428.  
  429.             /* Clean up any objects */
  430.             DisposeObject(text1_object);
  431.             DisposeObject(down_object);
  432.             DisposeObject(up_object);
  433.             DisposeObject(down_image);
  434.             DisposeObject(up_image);
  435.             DisposeObject(prop_object);
  436.  
  437.             /* Close the clipboard */
  438.             if (undo_handle) {
  439.                 CloseClipboard(undo_handle);
  440.             }
  441.             if (clip_handle) {
  442.                 CloseClipboard(clip_handle);
  443.             }
  444.  
  445.             FreeScreenDrawInfo(window->WScreen, draw_info);
  446.         } else {
  447.             printf("Couldn't get draw info.\n");
  448.         }
  449.         CloseWindow(window);
  450.     } else {
  451.         printf("Couldn't open window.\n");
  452.     }
  453.  
  454.     ShutdownPrefsWindow();
  455. }
  456.  
  457. /*
  458.  * GetGadgetRect()
  459.  *
  460.  * This function gets the actual Rectangle where a gadget exists
  461.  * in a window.  The special cases it handles are all the REL#?
  462.  * (relative positioning flags).
  463.  *
  464.  * You need the actual position if you want to RectFill() to clear
  465.  * the space a gadget covers or something like that.
  466.  *
  467.  * The function takes a struct Window pointer, a struct Gadget
  468.  * pointer, and a struct Rectangle pointer.  It uses the window and
  469.  * gadget to fill in the rectangle.
  470.  */
  471.  
  472. static void GetGadgetRect(struct Window *window, struct Gadget *gadget, struct Rectangle *rect)
  473. {
  474.     rect->MinX = rect->MaxX = gadget->LeftEdge;
  475.     if (gadget->Flags & GFLG_RELRIGHT) rect->MinX += window->Width - 1;
  476.     rect->MinY = rect->MaxY = gadget->TopEdge;
  477.     if (gadget->Flags & GFLG_RELBOTTOM) rect->MinY += window->Height - 1;
  478.     rect->MaxX += gadget->Width;
  479.     if (gadget->Flags & GFLG_RELWIDTH) rect->MaxX += window->Width - 1;
  480.     rect->MaxY += gadget->Height;
  481.     if (gadget->Flags & GFLG_RELHEIGHT) rect->MaxY += window->Height - 1;
  482. }
  483.  
  484. /*
  485.  * MainLoop()
  486.  *
  487.  * Handles all window IDCMP messages
  488.  */
  489.  
  490. static void MainLoop(void)
  491. {
  492.     ULONG done = FALSE;
  493.     UWORD menu_num;
  494.  
  495.     while (!done) {
  496.         HandleTextFieldPrefsIDCMP();
  497.         while (msg = (struct IntuiMessage *)GetMsg((struct MsgPort *)window->UserPort)) {
  498.             if (msg->Class == IDCMP_CLOSEWINDOW) {
  499.                 done = TRUE;
  500.             } else if ((msg->Class == IDCMP_VANILLAKEY) && (msg->Code == 0x09)) {
  501.                 // Activate first gadget that supports tab cycling if TAB is pressed
  502.                 ActivateTabGadget(window);
  503.             } else if (msg->Class == IDCMP_MENUPICK) {
  504.                 menu_num = msg->Code;
  505.                 while (!done && (menu_num != MENUNULL)) {
  506.                     done |= DoMenu(MENUNUM(menu_num), ITEMNUM(menu_num));
  507.                     menu_num = ItemAddress(menu_strip, menu_num)->NextSelect;
  508.                 }
  509.                 ActivateGadget(text1_object, window, NULL);
  510.             }
  511.             ReplyMsg((struct Message *)msg);
  512.         }
  513.         if (!done) {
  514.             Wait(sigs);
  515.         }
  516.     }
  517. }
  518.  
  519. /*
  520.  * ActivateTabGadget()
  521.  *
  522.  * This function scans a window's gadget list and activates the
  523.  * first gadget that supports tab cycling.
  524.  *
  525.  * It should be called when your window gets a VANILLAKEY message
  526.  * with a TAB code (0x09).  This gives the user a way to start
  527.  * tab cycling through gadgets.
  528.  */
  529.  
  530. static void ActivateTabGadget(struct Window *window)
  531. {
  532.     struct Gadget *gad;
  533.  
  534.     for (gad = window->FirstGadget; gad != NULL; gad = gad->NextGadget) {
  535.         if ((gad->Flags & GFLG_TABCYCLE) && !(gad->Flags & GFLG_DISABLED)) {
  536.             ActivateGadget(gad, window, NULL);
  537.             break;
  538.         }
  539.     }
  540. }
  541.  
  542. /*
  543.  * DoMenu()
  544.  *
  545.  * Handle the Edit menu items
  546.  */
  547.  
  548. static BOOL DoMenu(UWORD menu, UWORD item)
  549. {
  550.     switch (menu) {
  551.         case PROJECT_MENU:
  552.             switch (item) {
  553.                 case ABOUT_ITEM:
  554.                     EasyRequest(window, &about_req, NULL, TEXTFIELD_GetCopyright());
  555.                     break;
  556.  
  557.                 case QUIT_ITEM:
  558.                     return TRUE;
  559.                     break;
  560.             }
  561.             break;
  562.  
  563.         case EDIT_MENU:
  564.             {
  565.                 ULONG tag = 0;
  566.  
  567.                 switch (item) {
  568.                     case CUT_ITEM:
  569.                         tag = TEXTFIELD_Cut;
  570.                         break;
  571.  
  572.                     case COPY_ITEM:
  573.                         tag = TEXTFIELD_Copy;
  574.                         break;
  575.  
  576.                     case COPYALL_ITEM:
  577.                         tag = TEXTFIELD_CopyAll;
  578.                         break;
  579.  
  580.                     case PASTE_ITEM:
  581.                         tag = TEXTFIELD_Paste;
  582.                         break;
  583.  
  584.                     case UNDO_ITEM:
  585.                         tag = TEXTFIELD_Undo;
  586.                         break;
  587.  
  588.                     case ERASE_ITEM:
  589.                         tag = TEXTFIELD_Erase;
  590.                         break;
  591.                 }
  592.                 if (tag > 0) {
  593.                     SetGadgetAttrs(text1_object, window, NULL, tag, 0, TAG_DONE);
  594.                 }
  595.             }
  596.             break;
  597.     }
  598.  
  599.     return FALSE;
  600. }
  601.  
  602. /*
  603.  * SetupPrefsWindow()
  604.  *
  605.  * Opens the preferences window generated by GadToolsBox
  606.  */
  607.  
  608. static BOOL SetupPrefsWindow(void)
  609. {
  610.     if (SetupScreen() == 0) {
  611.         if (OpenTextFieldPrefsWindow() == 0) {
  612.             return TRUE;
  613.         } else {
  614.             CloseDownScreen();
  615.         }
  616.     }
  617.  
  618.     return FALSE;
  619. }
  620.  
  621. /*
  622.  * ShutdownPrefsWindow()
  623.  *
  624.  * Closes the preferences window generated by GadToolsBox
  625.  */
  626.  
  627. static void ShutdownPrefsWindow(void)
  628. {
  629.     CloseTextFieldPrefsWindow();
  630.     CloseDownScreen();
  631. }
  632.